#ifndef _USER_UART_H
#define _USER_UART_H
// uart protocol 115200,START(2)+ID(1)+SN(1)+LEN(1)+DATA(n)+SUM(1)
//START:SYS->MCU=0xEE55,MCU->SYS=0x55EE
//Function ID:
//Serial number:
//Length:data field
//Data:
//checksum:~(id+sn+len+data)
//uart Finite State Machine struct

#define UART_STREAM_TIMEOUT     200 //ms
#define UART_DATA_LEN_MAX       32
#define UART_START1             0xee
#define UART_START2             0x55

typedef enum{
    UartFsmStep_Start1=0,
    UartFsmStep_Start2,
    UartFsmStep_Id,
    UartFsmStep_Sn,
    UartFsmStep_Len,
    UartFsmStep_Data,
    UartFsmStep_Sum,
    UartFsmStep_Done        
}UartFsmStepType;

typedef struct{
    UartFsmStepType StateStep;
    unsigned char   Id;
    unsigned char   Sn;
    unsigned char   Len;
    unsigned char   DataBuf[UART_DATA_LEN_MAX];
    unsigned char   DataCnt;
    unsigned char   Checksum;
}UartFsmStateType;

void Uart_Init(void);
void Uart_Cyc();
void Uart1Print(unsigned char *str);

#endif